<template>
  <div class="app-container">
    <el-row type="flex" align="center" :gutter="20">
      <el-form class="filterData-block" label-position="left" :inline="true" label-width="auto">
        <el-form-item label="关键字:">
          <el-input
            placeholder="姓名 | 职位"
            v-model="filterData.keyword"
            maxlength="20"
            size="small"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-form-item label="审核状态:">
          <el-cascader
            v-model="filterData.sceneType"
            clearable
            placeholder="全部类型"
            :options="trainTypeOption"
            size="small"
            :props="{value:'id',label:'data'}"
            filterDataable
          ></el-cascader>
        </el-form-item>
        <el-form-item>
          <el-button size="small" icon="el-icon-search" type="primary" @click="refreshTable">搜索</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <el-row style="margin-top: 20px">
      <el-table v-loading="tableConf.loading" :stripe="true" :border="true" :data="tableData">
        <el-table-column align="center" width="50px" prop="id" label="ID"/>
        <el-table-column align="center" min-width="100px" prop="realName" label="姓名"/>
        <el-table-column align="center" min-width="100px" prop="comPosition" label="职位"/>
        <el-table-column align="center" min-width="100px" prop="enterprise.enterpriseName" label="所属公司"/>
        <el-table-column align="center" label="营业执照" width="130px">
          <template slot-scope="{row}">
            <el-image
              style="width: 100px; height: 100px"
              :preview-src-list="[row.upLicense]"
              :src="row.upLicense"
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column align="center" min-width="100px"  label="审核状态">
          <template slot-scope="{row}">
              {{row.stateText}}
            <template v-if="row.rregisteState===3">
              ({{row.user.remarks}})
            </template>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-row style="margin-top: 20px">
      <el-pagination
        :page-sizes="tableConf.sizes"
        :page-size="tableConf.size"
        :total="tableConf.total"
        :current-page="tableConf.page"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-row>
  </div>
</template>

<script>
import PersonnelCodeDetail from '@/components/PersonnelCode/Detail'
import {getList,toExamineUserApi} from '@/api/personnelCode'

export default {
  components: { PersonnelCodeDetail },
  data() {
    return {
      tableData: [],
      tableConf: {
        page: 1,
        sizes: [5, 20, 50, 100],
        total: 0,
        size: 5,
        loading: false
      },
      visible: {//控制弹窗显示
        0: false
      },
      detailId: null,
      keyword: '',//关键字查询
      filterData: {
        keyword: '',
        sceneType: [],
        time: []
      },
      placeTypeLoading: true,
      trainTypeOption: [
        {id: 2,data: "待审核"},
        {id: 9,data: "已通过"},
        {id: 3,data: "已拒绝"},
      ]
    }
  },
  props:['id','closeDialog'],
  mounted() {
    this.createParams(this)
    this.getTableList()
  },
  methods: {
    downloadCode(url) {
      window.open(url)
    },

    updateRowState(id, stateType) {
      toExamineUserApi({ id, stateType }).then(() => {
        this.$message.success('审核成功')
      }).finally(() => {
        this.getTableList()
      })
    },

    openRecord(id) {
      //新标签页打开列表
      this.$router.push({
        name: 'PlaceScanRecord',
        query: {
          id: id
        }
      })
    },
    // 每页显示数量change
    handleSizeChange(e) {
      this.tableConf.size = e
      this.getTableList()
    },
    // 当前页change
    handleCurrentChange(e) {
      this.tableConf.page = e
      this.getTableList()
    },
    //获取列表
    getTableList() {
      this.tableConf.loading = true
      const sceneType = this.filterData.sceneType.length === 0 ? 0 : this.filterData.sceneType[0];
      getList({
        page: this.tableConf.page,
        limit: this.tableConf.size,
        keyWord: this.filterData.keyword,
        sceneType,
        enrollId: this.id,
      }).then((res) => {
        console.log(res)
        this.tableData = res.list
        this.tableConf.total = res.count
      }).finally(() => {
        this.tableConf.loading = false
      })
    },
    refreshTable() {
      this.tableConf.page = 1
      this.getTableList()
    }
  }
}
</script>
<style lang="scss" scoped>
.filterData-block {
  .el-form-item {
    margin-bottom: 0;
  }
}
</style>
